package com.amumu.drama.admin.modules.invitation.controller;

import com.amumu.drama.common.base.api.CommonPage;
import com.amumu.drama.common.base.api.CommonResult;
import com.amumu.drama.common.base.dto.req.IdReq;
import com.amumu.drama.common.modules.invitation.dto.AnchorDto;
import com.amumu.drama.common.modules.invitation.dto.req.InvitationAnchorPageQuery;
import com.amumu.drama.common.modules.invitation.dto.req.InvitationLogQuery;
import com.amumu.drama.common.modules.invitation.dto.resp.InvitationAnchorDetailResp;
import com.amumu.drama.common.modules.invitation.dto.resp.InvitationAnchorListResp;
import com.amumu.drama.common.modules.invitation.dto.resp.MemberInvitationLogListResp;
import com.amumu.drama.common.modules.invitation.service.InvitationAnchorService;
import com.amumu.drama.common.modules.invitation.service.InvitationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 游戏优惠码管理
 * Created by macro on 2018/4/26.
 */
@RestController
@Api(tags = "微丸子-优惠码管理")
@RequestMapping("/invitationAnchor")
public class InvitationAnchorController {
    @Autowired
    private InvitationAnchorService invitationAnchorService;

    @Autowired
    private InvitationLogService invitationLogService;

    @ApiOperation("生成线下主播优惠码")
    @RequestMapping(value = "/genAnchorCode", method = RequestMethod.POST)
    public CommonResult generateInvitationAnchorCode(@Validated @RequestBody AnchorDto anchorDto) {
        return invitationAnchorService.generateInvitationAnchorCode(anchorDto, "1");
    }

    @ApiOperation("修改主播优惠码")
    @RequestMapping(value = "/updAnchorCode", method = RequestMethod.POST)
    public CommonResult updateInvitationAnchorCode(@Validated @RequestBody AnchorDto anchorDto) {
        return invitationAnchorService.updateInvitationAnchorCode(anchorDto);
    }

    @ApiOperation("删除主播优惠码")
    @RequestMapping(value = "/deleteCode/{invitationCodeId}", method = RequestMethod.GET)
    public CommonResult deleteCode(@PathVariable Long invitationCodeId) {
        return invitationAnchorService.deleteCode(invitationCodeId);
    }

    @ApiOperation("启停邀请码")
    @RequestMapping(value = "/enableCode/{invitationCodeId}/{enableStatus}", method = RequestMethod.GET)
    public CommonResult enableCode(@PathVariable Long invitationCodeId, @PathVariable Integer enableStatus) {
        return invitationAnchorService.enableCode(invitationCodeId, enableStatus);
    }

    @ApiOperation("查询游戏优惠码列表")
    @RequestMapping(value = "/pageInvitationAnchor", method = RequestMethod.POST)
    public CommonResult<CommonPage<InvitationAnchorListResp>> pageInvitationAnchor(@Validated @RequestBody InvitationAnchorPageQuery request) {
        return CommonResult.success(invitationAnchorService.pageInvitationAnchor(request));
    }


    @ApiOperation("获取游戏优惠码详情")
    @PostMapping(value = "/getInvitationAnchorDetail")
    public CommonResult<InvitationAnchorDetailResp> getInvitationAnchorDetail(@RequestBody @Validated IdReq request) {
        return invitationAnchorService.getInvitationAnchorDetail(request.getId());
    }

    @ApiOperation("查询邀请日志明细")
    @PostMapping("/queryMemberInvitationLog")
    public CommonResult<CommonPage<MemberInvitationLogListResp>> queryInvitationLog(@RequestBody @Validated InvitationLogQuery request) {
        return CommonResult.success(invitationLogService.queryInvitationLog(request));
    }
}
